﻿using DTcms.Common;
using DTcms.Model;
using DTcms.SMS;
using DTcms.Web.Mvc.UI;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Web.Mvc;
using System.Xml;

namespace DTcms.Web.Mvc.Areas.Admin.Controllers
{
    public class SettingsController : ManageController
    {
        protected BaseApi _service = new BaseApi();
        protected int totalCount = 0;
        protected Model.manager managerModel = new Model.manager();
        protected string _action;
        protected int _id;
        protected int _site_id;
        protected string defaultpassword = "0|0|0|0"; //默认显示密码
        protected override void OnAuthorization(AuthorizationContext filterContext)
        {
            base.OnAuthorization(filterContext);
            managerModel = GetAdminInfo();
            _action = DTRequest.GetQueryString("action");
            _id = DTRequest.GetQueryInt("id");
            _site_id = DTRequest.GetQueryInt("site_id");
            ViewBag.action = _action;
            ViewBag.id = _id;
            ViewBag.site_id = _site_id;
        }

        #region 页面创建
        public ActionResult Blank()
        {
            return View();
        }

        public ActionResult Icon()
        {
            return View();
        }

        [ChkAdminScript("sys_url_rewrite", DTEnums.ActionEnum.View)]
        public ActionResult Url_Rewrite_Edit()
        {
            Model.url_rewrite model = new Model.url_rewrite();
            string urlName = string.Empty;
            if (!string.IsNullOrEmpty(_action) && _action == DTEnums.ActionEnum.Edit.ToString())
            {
                this._action = DTEnums.ActionEnum.Edit.ToString();//修改类型
                urlName = DTRequest.GetQueryString("name");
                if (string.IsNullOrEmpty(urlName))
                {
                    return ResultMsg("传输参数不正确！", "back");
                }
                model = _service.UrlRewriteInfo(urlName);
                if (model == null)
                {
                    return ResultMsg("记录不存在或已被删除！", "back");
                }
                ViewBag.ClientScript = Jscript("$('#name').attr('ajaxurl', '/admin_ajax/urlrewrite_name_validate?old_name=" + Utils.UrlEncode(model.name) + "');");
            }
            else
            {
                ViewBag.ClientScript = Jscript("$('#name').attr('ajaxurl', '/admin_ajax/urlrewrite_name_validate');");
            }
            List<SelectListItem> channelList = new List<SelectListItem>();
            channelList.Add(new SelectListItem() { Text = "不属于频道", Value = "" });
            channelList.AddRange(_service.ChannelBind("", "sort_id asc,id desc"));
            ViewBag.channelList = channelList;
            ViewBag.UrlName = urlName;
            return View(model);
        }

        [ChkAdminScript("sys_url_rewrite", DTEnums.ActionEnum.View)]
        public ActionResult Url_Rewrite_List()
        {
            return View();
        }

        [ChkAdminScript("sys_navigation", DTEnums.ActionEnum.View)]
        public ActionResult Nav_Edit()
        {
            Model.navigation model = new Model.navigation();
            if (!string.IsNullOrEmpty(_action) && _action == DTEnums.ActionEnum.Edit.ToString())
            {
                if (_id == 0)
                {
                    return ResultMsg("传输参数不正确！", "back");
                }
                model = _service.SysNavigationInfo(_id);
                if (model == null)
                {
                    return ResultMsg("导航不存在或已被删除！", "back");
                }
                ViewBag.ClientScript = Jscript("$('#name').attr('ajaxurl', '/admin_ajax/navigation_validate?old_name=" + Utils.UrlEncode(model.name) + "');");
            }
            else
            {
                if (_id > 0)
                {
                    model.parent_id = _id;
                }
                ViewBag.ClientScript = Jscript("$('#name').attr('ajaxurl', '/admin_ajax/navigation_validate');");
            }
            List<SelectListItem> parentList = new List<SelectListItem>();
            parentList.Add(new SelectListItem() { Text = "无父级导航", Value = "0" });
            parentList.AddRange(_service.SysNavigationTreeBind(DTEnums.NavigationEnum.System.ToString()));
            ViewBag.selectListItems = parentList;
            return View(model);
        }

        [ChkAdminScript("sys_navigation", DTEnums.ActionEnum.View)]
        public ActionResult Nav_List()
        {
            return View();
        }

        [ChkAdminScript("sys_site_templet", DTEnums.ActionEnum.View)]
        public ActionResult Templet_List()
        {
            List<SelectListItem> siteListItems = _service.SiteTreeBind("is_lock=0", "is_default desc,sort_id asc,id desc");
            ViewBag.siteListItems = siteListItems;
            if (_site_id == 0 && siteListItems.Count > 0)
            {
                _site_id = Utils.StrToInt(siteListItems.First().Value, 0);
            }
            ViewBag.site_id = _site_id.ToString();
            DataTable dt2 = new DataTable();
            DataTable dt = _service.TempletBind(_site_id, out dt2);
            ViewBag.rptCurrent = dt2;
            return View(dt);
        }

        [ChkAdminScript("sys_site_templet", DTEnums.ActionEnum.View)]
        public ActionResult Templet_File_Edit()
        {
            string pathName = DTRequest.GetQueryString("path");
            string fileName = DTRequest.GetQueryString("filename");
            int areas = DTRequest.GetQueryInt("areas");
            if (string.IsNullOrEmpty(pathName) || string.IsNullOrEmpty(fileName))
            {
                return ResultMsg("传输参数不正确！", "back");
            }
            string fileurl = "~/templates/";
            if (areas == 1)
            {
                fileurl = "~/Areas/Web/Views/";
            }
            string filePath = Utils.GetMapPath(@"" + fileurl + pathName.Replace(".", "") + "/" + fileName.Replace("..", ""));
            string ext = Utils.GetFileExt(filePath);
            if (!System.IO.File.Exists(filePath) || ext == "aspx" || ext == "config")
            {
                return ResultMsg("该文件不存在！", "back");
            }
            ViewBag.Areas = areas;
            ViewBag.PathName = pathName;
            ViewBag.FileName = fileName;
            ViewBag.Content = _service.ReadFile(filePath);
            return View();
        }

        [ChkAdminScript("sys_site_templet", DTEnums.ActionEnum.View)]
        public ActionResult Templet_File_List()
        {
            string skinName = DTRequest.GetQueryString("skin");
            string filepath = DTRequest.GetQueryString("filepath");
            int areas = DTRequest.GetQueryInt("areas");
            if (string.IsNullOrEmpty(skinName))
            {
                return ResultMsg("传输参数不正确！", "back");
            }
            //防跨目录
            if (!string.IsNullOrEmpty(filepath) && filepath != "")
            {
                filepath = filepath.Replace("..", "") + "/";
            }
            ViewBag.Areas = areas;
            ViewBag.SkinName = skinName;
            ViewBag.FilePath = filepath;
            return View(_service.TempletFileBind(skinName, filepath, areas));
        }

        [ChkAdminScript("sys_config", DTEnums.ActionEnum.View)]
        public ActionResult Sys_Config()
        {
            BLL.siteconfig bll = new BLL.siteconfig();
            Model.siteconfig model = bll.loadConfig(false);

            if (!string.IsNullOrEmpty(model.smspassword))
            {
                model.smspassword = defaultpassword;
            }
            if (!string.IsNullOrEmpty(model.emailpassword))
            {
                model.emailpassword = defaultpassword;
            }
            //string smsTip = string.Empty;
            //string smsCount = string.Empty;
            //_service.SetSmsCount(out smsTip, out smsCount);
            //ViewBag.SmsTip = smsTip;
            //ViewBag.SmsCount = smsCount;

            ViewBag.SmsTip = "查询结果";
            ViewBag.SmsCount = SmsFactory.Sms().GetAccountQuantity();
            return View(model);
        }

        [ChkAdminScript("system_cache", DTEnums.ActionEnum.View)]
        public ActionResult Sys_Cache()
        {
            return View();
        }

        [ChkAdminScript("sys_plugin_config", DTEnums.ActionEnum.View)]
        public ActionResult Plugin_List()
        {
            return View();
        }

        [ChkAdminScript("sys_builder_html", DTEnums.ActionEnum.View)]
        public ActionResult Builder_Html()
        {
            List<SelectListItem> siteListItems = _service.SiteTreeBind("is_lock=0", "is_default desc,sort_id asc,id desc");
            string build_path = string.Empty;
            if (_site_id == 0 && siteListItems.Count > 0)
            {
                _site_id = Utils.StrToInt(siteListItems.First().Value, 0);
            }
            ViewBag.site_id = _site_id.ToString();
            if (_site_id > 0)
            {
                DTcms.Model.sites model = new DTcms.BLL.sites().Get(_site_id);
                build_path = model.build_path;
                //是否继承
                if (model.inherit_id > 0)
                {
                    _site_id = model.inherit_id;
                }
                ViewBag.tabContent = true;
            }
            ViewBag.siteListItems = siteListItems;
            ViewBag.BuildPath = build_path;
            ViewBag.siteConfig = siteConfig;
            return View(_service.ChannelBind(_site_id, "sort_id asc,id desc"));
        }
        #endregion

        #region 页面数据绑定
        #region 数据绑定
        [ChkAdminJson("sys_url_rewrite", DTEnums.ActionEnum.View)]
        public JsonResult UrlRewriteList(int site = 0, int channel = 0, string type = "")
        {
            List<Model.url_rewrite> list = _service.UrlRewriteBind(site, channel, type);
            return Json(new { status = 1, msg = "", item = list, totalCount = list.Count });
        }
        #endregion

        #region 数据绑定
        [ChkAdminJson("system_cache", DTEnums.ActionEnum.View)]
        public JsonResult CacheList()
        {
            return Json(new { status = 1, msg = "", item = _service.SysCacheBind() });
        }
        #endregion

        #region 数据绑定
        [ChkAdminJson("sys_plugin_config", DTEnums.ActionEnum.View)]
        public JsonResult PluginList()
        {
            return Json(new { status = 1, msg = "", item = _service.SysPluginBind() });
        }
        #endregion

        #region 数据绑定
        [ChkAdminJson("sys_navigation", DTEnums.ActionEnum.View)]
        public JsonResult NavList(int isGrid = 0)
        {
            if (isGrid == 1)
            {
                return Json(new { code = 0, msg = "", data = _service.SysNavigationBind(), count = 0 });
            }
            else
            {
                return Json(new { status = 1, msg = "", item = _service.SysNavigationBind() });
            }
        }
        #endregion
        #endregion

        #region 页面的其他操作
        #region 生成模板
        [HttpGet]
        [ChkAdminJson("sys_site_templet", DTEnums.ActionEnum.Build)]
        public JsonResult TempletListStart(string skinname, int site_id)
        {
            return _service.TempletStart(skinname, site_id);
        }

        [HttpPost]
        [ChkAdminJson("system_cache", DTEnums.ActionEnum.Delete)]
        public JsonResult CaCheDelete(List<string> ids)
        {
            return _service.SysCacheDelete(ids);
        }

        [HttpPost]
        [ChkAdminJson("sys_url_rewrite", DTEnums.ActionEnum.Delete)]
        public JsonResult UrlRewriteDelete(List<string> ids)
        {
            return _service.UrlRewriteDelete(ids);
        }

        [HttpPost]
        [ChkAdminJson("system_cache", DTEnums.ActionEnum.Delete)]
        public JsonResult CaCheDelAll()
        {
            return _service.SysCacheDelAll();
        }

        [HttpPost]
        [ChkAdminJson("user_pointscard", DTEnums.ActionEnum.UnLoad)]
        public JsonResult PluginUninstall(string ids)
        {
            return _service.SysPluginUninstall(ids);
        }

        [HttpPost]
        [ChkAdminJson("sys_plugin_config", DTEnums.ActionEnum.Instal)]
        public JsonResult PluginInstall(string ids)
        {
            return _service.SysPluginInstall(ids);
        }

        [HttpPost]
        [ChkAdminJson("sys_plugin_config", DTEnums.ActionEnum.Build)]
        public JsonResult PluginRemark(string ids)
        {
            return _service.SysPluginRemark(ids);
        }

        [HttpPost]
        [ChkAdminJson("sys_navigation", DTEnums.ActionEnum.Delete)]
        public JsonResult NavDelete(List<int> ids)
        {
            return _service.SysNavigationDelete(ids);
        }

        [HttpPost, CustomValidateAntiForgeryToken]
        public ActionResult NavSave(Model.navigation t)
        {
            SaveModel save = _service.SysNavigationSave(_action, _id, t);
            save.url = save.status == 0 ? "back" : "../settings/nav_list";
            return Json(save);
        }

        [HttpPost, ValidateInput(false), CustomValidateAntiForgeryToken]
        [ChkAdminJson("sys_config", DTEnums.ActionEnum.Edit)]
        public ActionResult SysConfigSave(Model.siteconfig t)
        {
            SaveModel save = _service.SysConfigSave(t);
            save.url = save.status == 0 ? "back" : "../settings/sys_config";
            return Json(save);
        }

        [HttpPost, CustomValidateAntiForgeryToken]
        public ActionResult UrlRewriteSave(string name, Model.url_rewrite t)
        {
            SaveModel save = _service.UrlRewriteSave(name, _action, t);
            save.url = save.status == 0 ? "back" : "../settings/url_rewrite_list";
            return Json(save);
        }

        [HttpPost, ValidateInput(false), CustomValidateAntiForgeryToken]
        [ChkAdminJson("sys_site_templet", DTEnums.ActionEnum.Edit)]
        public ActionResult TempletFileSave(string pathName, string fileName, string txtContent)
        {
            SaveModel save = _service.TempletFileSave(pathName, fileName, txtContent);
            save.url = "";
            return Json(save);
        }
        #endregion
        #region 个别字段修改
        [HttpPost]
        [ChkAdminJson("sys_navigation", DTEnums.ActionEnum.Edit)]
        public JsonResult NavFiledSave(string field, string value, int id = 0)
        {
            if (string.IsNullOrEmpty(field) || id == 0)
            {
                return Json(new { status = 0, msg = "参数错误！" });
            }
            BLL.navigation bll = new BLL.navigation();
            if (bll.UpdateFile("id=" + id, field + "=" + value))
            {
                return Json(new { status = 1, msg = "修改成功！" });
            }
            return Json(new { status = 0, msg = "修改失败！" });
        }

        #region 修改后台导航管理是否显示
        [HttpPost]
        [ChkAdminJson("sys_navigation", DTEnums.ActionEnum.Edit)]
        public JsonResult NavLock(int id, bool is_lock)
        {
            BLL.navigation bll = new BLL.navigation();
            if (bll.UpdateFile("id=" + id, "is_lock=" + (is_lock ? 0 : 1)))
            {
                return Json(new { status = 1, msg = "状态修改成功！" });
            }
            return Json(new { status = 0, msg = "状态修改失败！" });
        }
        #endregion
        #endregion
        #endregion

        #region 站点地图
        [ChkAdminJson("sys_site_templet", DTEnums.ActionEnum.Build)]
        public JsonResult templet_conversion(string skinname, int site_id = 0)
        {
            if (string.IsNullOrEmpty(skinname) || site_id == 0)
            {
                return Json(new { status = 0, msg = "参数错误！" });
            }
            MarkTemplates(skinname, skinname);
            return Json(new { status = 1, msg = "生成成功！" });
        }
        #endregion

        #region 转化模板
        /// <summary>
        /// 生成全部模板
        /// </summary>
        private void MarkTemplates(string buildPath, string skinName)
        {
            //取得ASP目录下的所有文件
            string fullDirPath = Utils.GetMapPath(string.Format("{0}templates/{1}/Views/", siteConfig.webpath, buildPath));//生成到目录
            //取得模板目录的物理路径
            string fullTempPath = Utils.GetMapPath(string.Format("{0}templates/{1}/Original/", siteConfig.webpath, skinName));//获取需要生成的目录
            //获得URL配置列表
            BLL.url_rewrite bll = new BLL.url_rewrite();
            List<Model.url_rewrite> ls = bll.GetList(string.Empty);

            DirectoryInfo dirFile = new DirectoryInfo(fullDirPath);
            //删除不属于URL映射表里的文件，防止冗余
            if (Directory.Exists(fullDirPath))
            {
                foreach (FileInfo file in dirFile.GetFiles())
                {
                    //检查文件
                    Model.url_rewrite modelt = ls.Find(p => p.page.ToLower() == file.Name.ToLower());
                    if (modelt != null && modelt.type.ToLower() == "plugin")
                    {
                        continue; //如果是插件页面则不删除
                    }
                    file.Delete(); //删除文件
                }
            }

            //遍历URL配置列表
            foreach (Model.url_rewrite modelt in ls)
            {
                //如果URL配置对应的模板文件存在则生成
                string fullPath = Utils.GetMapPath(string.Format("{0}templates/{1}/Original/{2}", siteConfig.webpath, skinName, modelt.templet));
                fullPath = fullPath.Replace("cshtml", "html");
                if (System.IO.File.Exists(fullPath))
                {
                    PageTemplate.GetTemplate(siteConfig.webpath, "templates", skinName, modelt.templet.Replace("cshtml", "html"), modelt.page, modelt.inherit, buildPath, modelt.channel, modelt.pagesize, 1);
                }
            }
        }
        #endregion

        #region 生成站点地图
        [ChkAdminScript("sitemap", DTEnums.ActionEnum.View)]
        public ActionResult sitemap()
        {
            BLL.sitemapconfig bll = new BLL.sitemapconfig();
            Model.sitemapconfig model = bll.loadConfig(false);
            return View(model);
        }
        private PageInfo LinkIndexUrl(string domain, string name, string priority, string changefreq)
        {
            PageInfo p = new PageInfo();
            string link = UrlHelperExtend.linkurl(name);
            if (string.IsNullOrEmpty(link))
            {
                return p;
            }
            p.loc = domain + link;
            p.lastmod = DateTime.Now;
            p.priority = priority;
            p.changefreq = changefreq;
            return p;
        }
        private PageInfo LinkListQueryUrl(string domain, string name, string call_index, string title, int id, string priority, string changefreq)
        {
            PageInfo p = new PageInfo();
            string link = UrlHelperExtend.queryurl(name, call_index, id);
            if (string.IsNullOrEmpty(link))
            {
                return p;
            }
            p.loc = domain + link;
            p.lastmod = DateTime.Now;
            p.priority = priority;
            p.changefreq = changefreq;
            p.title = title;
            return p;
        }
        private List<PageInfo> LinkListUrl(string priority, string changefreq, string domain, int page_size, int totalcount, string _key, params object[] _params)
        {
            List<PageInfo> list = new List<PageInfo>();
            string linkUrl = UrlHelperExtend.linkurl(_key, _params);
            if (string.IsNullOrEmpty(linkUrl))
            {
                return list;
            }
            int pageCount = totalcount / page_size;//计算页数
            string pageId = "__id__";

            if (pageCount < 1)
            {
                pageCount = 1;
            }
            else if (totalcount % page_size > 0)
            {
                pageCount += 1;
            }
            if (pageCount > 1)
            {
                PageInfo p;
                for (int i = 1; i <= pageCount; i++)
                {
                    p = new PageInfo();
                    string link = Utils.ReplaceStr(linkUrl, pageId, i.ToString());
                    p.loc = domain + link;
                    p.lastmod = DateTime.Now;
                    p.priority = priority;
                    p.changefreq = changefreq;
                    list.Add(p);
                }
            }
            return list;
        }
        [HttpPost, CustomValidateAntiForgeryToken]
        [ChkAdminJson("sitemap", DTEnums.ActionEnum.Build)]
        public JsonResult sitemapBuild(Model.sitemapconfig t, int ddlSiteId, string ddlxml, bool is_xml, bool is_html, bool is_txt)
        {
            List<PageInfo> url = new List<PageInfo>();
            PageInfo p = new PageInfo();

            #region 获取当前选择网站的Url
            Model.sites model = new BLL.sites().GetModel(ddlSiteId);
            if (model == null)
            {
                return Json(new { status = 1, msg = "站点不存在！" });
            }

            var allUrls = SiteUrls.GetEffective(siteConfig.webpath, model.templet_path);
            allUrls = allUrls.Except(allUrls.Where(a => a.page.Contains("member/"))).ToList();//去除会员中心
            List<Model.site_channel> list = new BLL.site_channel().GetModelList(0, "site_id=" + ddlSiteId, "", "id desc");
            if (allUrls != null)
            {
                foreach (var item in allUrls)
                {
                    if (LinkOther(item.name))
                    {
                        string domain = model.domain.Contains("http") ? model.domain : "http://" + model.domain;
                        if (item.type == "index")//频道首页
                        {
                            url.Add(LinkIndexUrl(domain, item.name, t.sitemap_priority_index, t.sitemap_changefreq_index));
                        }
                        if (item.type == "list")//频道类别页
                        {
                            if (item.url_rewrite_items.Count == 0)
                            {
                                url.Add(LinkIndexUrl(domain, item.name, t.sitemap_priority_list, t.sitemap_changefreq_list));
                            }
                            else
                            {
                                foreach (var row in list)
                                {
                                    if (row.name == item.channel)
                                    {
                                        List<Model.article_category> category = new BLL.article_category().GetList(row.id);
                                        foreach (var cate in category)
                                        {
                                            int pageSize = Utils.StrToInt(item.pagesize, 10);//页容量
                                            int totalCount = new BLL.article().ArticleCount(row.name, cate.id, "status=0");//总记录数

                                            if (!string.IsNullOrEmpty(cate.call_index))
                                            {
                                                url.Add(LinkListQueryUrl(domain, item.name, "", cate.title, cate.id, t.sitemap_priority_list, t.sitemap_changefreq_list));
                                                url.AddRange(LinkListUrl(t.sitemap_priority_list, t.sitemap_changefreq_list, domain, pageSize, totalCount, item.name, cate.call_index, "__id__"));
                                            }
                                            url.Add(LinkListQueryUrl(domain, item.name, cate.call_index, cate.title, cate.id, t.sitemap_priority_list, t.sitemap_changefreq_list));
                                            url.AddRange(LinkListUrl(t.sitemap_priority_list, t.sitemap_changefreq_list, domain, pageSize, totalCount, item.name, cate.id, "__id__"));
                                        }
                                    }
                                }
                            }
                        }
                        if (item.type == "detail")//频道详细页
                        {
                            foreach (var row in list)
                            {
                                if (row.name == item.channel)
                                {
                                    List<Model.article> article = new BLL.article().GetModelList(row.name, 0, 0, "id,call_index,title", "status=0", "id desc");
                                    foreach (var art in article)
                                    {
                                        if (!string.IsNullOrEmpty(art.call_index))
                                        {
                                            url.Add(LinkListQueryUrl(domain, item.name, "", art.title, art.id, t.sitemap_priority_show, t.sitemap_changefreq_show));
                                        }
                                        url.Add(LinkListQueryUrl(domain, item.name, art.call_index, art.title, art.id, t.sitemap_priority_show, t.sitemap_changefreq_show));
                                    }
                                }
                            }
                        }
                        if (item.type == "other" || item.type == "plugin")//其他页 插件页
                        {
                            url.Add(LinkIndexUrl(domain, item.name, t.sitemap_priority_index, t.sitemap_changefreq_index));
                        }
                        if (item.name == "tags")//标签页特别处理
                        {
                            var tags = new BLL.article_tags().GetModelList(0, "is_red=1", "id,call_index,title", "sort_id asc,add_time desc");
                            foreach (var tg in tags)
                            {
                                if (!string.IsNullOrEmpty(tg.call_index))
                                {
                                    url.Add(LinkListQueryUrl(domain, item.name, "", tg.title, tg.id, t.sitemap_priority_list, t.sitemap_changefreq_list));
                                }
                                url.Add(LinkListQueryUrl(domain, item.name, tg.call_index, tg.title, tg.id, t.sitemap_priority_list, t.sitemap_changefreq_list));
                            }
                        }
                    }
                }
            }
            url.RemoveAll(x => x.loc == null);
            #endregion

            if (is_xml)
            {
                SitemapXml.CreateSiteMapXml(url, "/", "sitemap");
            }
            if (is_html)
            {
                SitemapXml.GenerateSiteMapHTML(url, "/", "sitemap");
            }
            if (is_txt)
            {
                SitemapXml.GenerateSiteMapTXT(url, "/", "sitemap");
            }
            new BLL.sitemapconfig().saveConifg(t);
            AddAdminLog(DTEnums.ActionEnum.Build.ToString(), "生成站点地图");
            return Json(new { status = 1, msg = "生成成功！", url = "" });
        }
        /// <summary>
        /// other页面过滤
        /// </summary>
        /// <returns></returns>
        public bool LinkOther(string name)
        {
            //判断是否可以打水印的图片类型
            ArrayList al = new ArrayList();
            al.Add("error");
            al.Add("cart");
            al.Add("shopping");
            al.Add("payment");
            al.Add("login");
            al.Add("oauth_login");
            al.Add("register");
            al.Add("repassword");
            if (al.Contains(name.ToLower()))
            {
                return false;
            }
            return true;
        }
        #endregion

        #region 文件管理
        [ChkAdminScript("sys_file", DTEnums.ActionEnum.View)]
        public ActionResult File()
        {
            return View();
        }
        /// <summary>
        /// 删除文件或文件夹
        /// </summary>
        /// <param name="wjm"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public JsonResult file_delete(string wjm, string type)
        {
            if (managerModel.role_type != 1)
            {
                return Json(new { status = 0, msg = "没有权限进行删除操作！" });
            }
            try
            {
                if (type == "")
                {
                    FileHelper.DeleteDirectory(wjm);//删除文件夹
                }
                else
                {
                    FileHelper.DeleteFile(wjm);//删除单个文件
                }
                AddAdminLog(DTEnums.ActionEnum.Edit.ToString(), "删除文件" + wjm + " 类型：" + type); //记录日志
                return Json(new { status = 1, msg = "删除成功！" });
            }
            catch (Exception ex)
            {
                return Json(new { status = 0, msg = ex.Message });
            }
        }

        /// <summary>
        /// 新建文件夹
        /// </summary>
        /// <param name="name">文件夹名</param>
        /// <param name="path">创建的地址</param>
        /// <returns></returns>
        [HttpPost]
        public JsonResult newFile(string name, string path)
        {
            if (string.IsNullOrEmpty(name))
            {
                return Json(new { status = 0, msg = "名称不能为空！" });
            }
            Utils.DirectoryExists(siteConfig.webpath + siteConfig.filepath + "/" + path + name);
            return Json(new { status = 1, msg = "创建成功！" });
        }
        #endregion
    }
}
